package com.telenav.module.activities;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.telenav.app.R;
import com.telenav.module.entity.ActivitiesEntity;
import com.telenav.res.image.AsyncImageLoader;

public class ActivitiesHotAdapter extends BaseAdapter {

	private Context mContext;

	private LayoutInflater mInflater;

	private List<ActivitiesEntity> mactivities;

	public ActivitiesHotAdapter(Context context, List<ActivitiesEntity> activities) {
		mContext = context;
		mInflater = LayoutInflater.from(context);
		mactivities = activities;
	}

	public int getCount() {
		return mactivities.size();
	}

	public Object getItem(int position) {
		return mactivities.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ActivitiesEntity entity = mactivities.get(position);
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.main_hot_activities, null);
			viewHolder = new ViewHolder();
			viewHolder.billImage = (ImageView) convertView.findViewById(R.id.billImage);
			viewHolder.title = (TextView) convertView.findViewById(R.id.title);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

//		Bitmap billImage = BitmapFactory.decodeResource(
//				mContext.getResources(), entity.getBillImage());
//		viewHolder.billImage.setImageBitmap(billImage);
		AsyncImageLoader.getInstance().loadImage(entity.getUrl(), viewHolder.billImage, R.drawable.noimage1);
		viewHolder.title.setText(entity.getTitle());
		return convertView;
	}

	static class ViewHolder {
		public ImageView billImage;
		public TextView title;
	}
}
